<?php
// 消息管理类
namespace Home\Controller;
// use Think\Controller;
class MessageController extends BaseController {
	public function index(){
		$starttime = strtotime(I('stime',date('Y-m-d',time()-24*3600*5)));
		$endtime = strtotime(I('ntime',date('Y-m-d H:s:i')));
		$page = I('page',1);
		$mod = D('Message');
		$where = array('app_id'=>$this->app['id'],'CreateTime'=>array(array('lt',$endtime),array('gt',$starttime)));
		$count = $mod->where($where)->count();
		$data = $mod->where($where)->page($page.',20')->order('CreateTime desc')->select();
		
		foreach ($data as &$v){
			$openids[$v['openid']] = $v['openid'];
		}
		if(!empty($openids))
			$users = $this->get_user($openids);
		foreach ($data as &$vv){
			$vv['user'] = $users[$vv['openid']];
		}
		$this->assign('page',$page);
		$this->assign('prev',($page > 1) ? $page-1 : 1);
		$this->assign('next',($page > ceil($count/20)) ? $page+1 : ceil($count/20));
		$this->assign('count',ceil($count/20));
		$this->assign('data',$data);
		$this->assign('time',strtotime(date('Y-m-d')));
		$this->assign('s',I('s',1));
		$this->assign('stime',date('Y-m-d',$starttime));
		$this->assign('ntime',date('Y-m-d',$endtime));
		$this->display();
	}
	public function reply(){
		$this->ajaxReturn('成功！');
	}
}
